package edu.luc.cs.trull;

import java.beans.PropertyChangeEvent;

import org.apache.log4j.Logger;

/**
 * An adapter for using any Scheduler as a ComponentScheduler.
 * @see edu.luc.cs.trull.ComponentScheduler
 * @see edu.luc.cs.trull.Scheduler
 */
public class ComponentSchedulerAdapter implements ComponentScheduler {

	private static final Logger logger = Logger.getLogger(ComponentSchedulerAdapter.class);

  /**
   * The original scheduler instance.
   */
  private Scheduler scheduler;
    
  public ComponentSchedulerAdapter(Scheduler scheduler) {
    this.scheduler = scheduler;
  }
  
  public void schedule(Runnable r) {
    scheduler.schedule(r); 
  }
  
  public void execute(Runnable r) throws InterruptedException {
    scheduler.execute(r); 
  }
    
	public void await() throws InterruptedException {
    scheduler.await();
	}

	public void start(final Component c) throws InterruptedException {
		start(c, null);
	}

	public void start(final Component c, final PropertyChangeEvent event)
			throws InterruptedException {
		scheduler.execute(new Runnable() {
			public void run() {
				c.start(event);
			}
		});
	}

	public void stop(final Component c) throws InterruptedException {
		scheduler.execute(new Runnable() {
			public void run() {
				c.stop();
			}
		});
	}

  public void suspend(final Component c) throws InterruptedException {
		scheduler.execute(new Runnable() {
			public void run() {
				c.suspend();
			}
		});
	}

	public void resume(final Component c) throws InterruptedException {
		scheduler.execute(new Runnable() {
			public void run() {
				c.resume();
			}
		});
	}

	public void propertyChange(final Component c,
			final PropertyChangeEvent event) throws InterruptedException {
		scheduler.execute(new Runnable() {
			public void run() {
				c.propertyChange(event);
			}
		});
	}
}